import 'package:shared_preferences/shared_preferences.dart';
import 'dart:convert';

class UserProof {
  static String _userId;

  static String get userId=>_userId;
  static SharedPreferences prefs;

  static void initSharedPreferences(SharedPreferences _prefs) {
    prefs = _prefs;
    _userId = prefs.get('user_id');
    String cacheUserInfo = prefs.get('user_info');
    if(null != cacheUserInfo) {
      userInfo = json.decode(cacheUserInfo);
    }
  }
  static void setUserId(String userId) {
    _userId = userId;
    prefs.setString('user_id', userId);
  }

  static Map userInfo = {}; //uname,sex,asset
  static void setUserInfo(Map<String, dynamic> _userInfo) {
    userInfo = _userInfo;
    prefs.setString('user_info', json.encode(_userInfo));
  }
  static void cleanUserinfo() {
    userInfo = null;
    _userId = null;
    prefs.remove('user_info');
    prefs.remove('user_id');
  }
}